package com.csdj.t309springboot.controller;
import com.csdj.t309springboot.common.WebResult;
import com.csdj.t309springboot.common.WebResultMsgCode;
import com.csdj.t309springboot.entity.IntegralRecord;
import com.csdj.t309springboot.service.IntegralRecordService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 积分记录表 Integral record 前端控制器
 * </p>
 *
 * @author 谭湛宇
 * @since 2022-01-13
 */
@RestController
@RequestMapping("/integral/record")
public class IntegralRecordController extends BaseController{
    @Resource
    private IntegralRecordService integralRecordService;

    @GetMapping("getListByUserId")
    public WebResult getIntegralRecordListByUserId(HttpServletRequest request){
        int userId = getUid(request);
        List<IntegralRecord> list = integralRecordService.getIntegralRecordListByUserId(userId);
        if(null != list){
            return new WebResult(WebResultMsgCode.SUCCESS).putData("list",list);
        }
        return new WebResult(WebResultMsgCode.FAIL);
    }
    @GetMapping("getIntegralRecordInfoByUserId")
    public WebResult getIntegralRecordInfoByUserId(HttpServletRequest request){
        int userId = getUid(request);
        IntegralRecord integralRecord = integralRecordService.getIntegralRecordInfoByUserId(userId);
        if(null != integralRecord){
            return new WebResult(WebResultMsgCode.SUCCESS).putData("entity",integralRecord);
        }
        return new WebResult(WebResultMsgCode.FAIL);
    }

}
